<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * MaterialOrder
 *
 * @ORM\Table(name="material_order")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\MaterialOrderRepository")
 */
class MaterialOrder
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var int
     *
     * @ORM\Column(name="material_id", type="integer")
     */
    private $materialId;

    /**
     * @var int
     *
     * @ORM\Column(name="number", type="integer")
     */
    private $number;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="create_at", type="datetime")
     */
    private $createAt;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="finish_at", type="datetime", nullable=true)
     */
    private $finishAt;
    /**
     * @var Material
     * @ORM\ManyToOne(targetEntity="Material", inversedBy="orders", cascade={"persist"})
     * @ORM\JoinColumn(nullable=true)
     */
    private $material;

    /**
     * @return Material
     */
    public function getMaterial(): Material
    {
        return $this->material;
    }

    /**
     * @param Material $material
     */
    public function setMaterial(Material $material)
    {

        $this->setMaterialId($material->getId());
        $this->material = $material;
    }

    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set materialId
     *
     * @param integer $materialId
     *
     * @return MaterialOrder
     */
    public function setMaterialId($materialId)
    {
        $this->materialId = $materialId;

        return $this;
    }

    /**
     * Get materialId
     *
     * @return int
     */
    public function getMaterialId()
    {
        return $this->materialId;
    }

    /**
     * Set number
     *
     * @param integer $number
     *
     * @return MaterialOrder
     */
    public function setNumber($number)
    {
        $this->number = $number;

        return $this;
    }

    /**
     * Get number
     *
     * @return int
     */
    public function getNumber()
    {
        return $this->number;
    }

    /**
     * Set createAt
     *
     * @param \DateTime $createAt
     *
     * @return MaterialOrder
     */
    public function setCreateAt($createAt)
    {
        $this->createAt = $createAt;

        return $this;
    }

    /**
     * Get createAt
     *
     * @return \DateTime
     */
    public function getCreateAt()
    {
        return $this->createAt;
    }

    /**
     * Set finishAt
     *
     * @param \DateTime $finishAt
     *
     * @return MaterialOrder
     */
    public function setFinishAt($finishAt)
    {
        $this->finishAt = $finishAt;

        return $this;
    }

    /**
     * Get finishAt
     *
     * @return \DateTime
     */
    public function getFinishAt()
    {
        return $this->finishAt;
    }

    public function __toString()
    {
        return json_encode([
            'id' => $this->getId(),
            'materialId' => $this->getMaterialId(),
            'number' => $this->getNumber(),
            'create_at' => $this->getCreateAt()->format('Y-m-d H:i:s'),
        ]);
    }
}

